{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 作业1：问卷+环境配置+大语言模型部署"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 0. 说明"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 0.1 关于 Jupyter Notebook"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Jupyter Notebook 是一种可编程的文档类型，类似于 R Markdown。Jupyter Notebook 文档以一个个单元格组成，每个单元格可以是 Markdown 或者 Python 代码：前者通常用来写文字说明，后者用来运行代码。比如你双击第一行的标题，就会看到标题的 Markdown 代码（以 `#` 符号开头），再按 `Ctrl+Enter`，就会显示 Markdown 渲染的结果。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "而对于代码单元格， `Ctrl+Enter` 会执行单元格内的代码，例如用鼠标点击下面的单元格然后按键后会出现形如 `Out[x]` 的输出结果。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.141592653589793"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "math.pi"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们的作业中既有需要说明的文字，又有需要编写的程序，前者用 Markdown 单元格，后者用代码单元格。单元格的类型可以在上方的下拉菜单中选择，也可以通过快捷键实现（通过菜单 Cell => Cell Type 查看）。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 0.2 关于 Markdown"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Markdown 是常用的文档格式化语法，如果有不熟悉的，可以参考[这里](https://www.jianshu.com/p/335db5716248)的教程。需要说明的是 Jupyter Notebook 里可以插入数学公式，例如 $f(x)=\\frac{1}{\\sqrt{2\\pi}}e^{-x^2/2}$。双击这个单元格来查看源代码。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 问卷"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "思考并回答**至少四个**问题："
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 你现在对深度学习有多少了解？"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我现在了解深度学习在生活中的一些应用，比如chatgpt，deepseek等"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 你预期今后的工作/研究与深度学习的关联大吗？"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我认为会比较大，我有考虑申请与深度学习相关专业的留学项目，之后回国参与这方面工作"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 你想从这门课学到什么？"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "与深度学习相关的基础框架知识以及一些目前常用的深度学习模型"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 你还有哪些喜欢的获取知识的渠道（例如B站，知乎，技术博客，公众号等）？如果有请向大家推荐一些，**具体到账号或网址**，不需要与深度学习相关。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 你对编程的喜欢/厌恶程度是多少？1为很厌恶，10为很喜欢。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "8，我觉得我挺喜欢编程，但是没有到发烧友的地步"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 你喜欢/**不**喜欢的上课方式是怎样的？"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我不喜欢完全由老师主导的课堂，我希望老师能够多给学生学习和联系代码的机会，而不是一直由老师讲，学生听"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 安装 PyTorch"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请参照课程文档《PyTorch安装》的提示配置好 PyTorch 环境。如果你的电脑具备 Nvidia 显卡，优先尝试安装 GPU 版本。用如下的代码验证 Conda 和 PyTorch 安装是否成功："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "     active environment : pytorch\n",
      "    active env location : E:\\anaconda\\envs\\pytorch\n",
      "            shell level : 1\n",
      "       user config file : C:\\Users\\Supernova\\.condarc\n",
      " populated config files : C:\\Users\\Supernova\\.condarc\n",
      "          conda version : 24.9.1\n",
      "    conda-build version : 24.5.1\n",
      "         python version : 3.12.4.final.0\n",
      "                 solver : libmamba (default)\n",
      "       virtual packages : __archspec=1=skylake\n",
      "                          __conda=24.9.1=0\n",
      "                          __cuda=12.7=0\n",
      "                          __win=0=0\n",
      "       base environment : E:\\anaconda  (writable)\n",
      "      conda av data dir : E:\\anaconda\\etc\\conda\n",
      "  conda av metadata url : None\n",
      "           channel URLs : https://repo.anaconda.com/pkgs/main/win-64\n",
      "                          https://repo.anaconda.com/pkgs/main/noarch\n",
      "                          https://repo.anaconda.com/pkgs/r/win-64\n",
      "                          https://repo.anaconda.com/pkgs/r/noarch\n",
      "                          https://repo.anaconda.com/pkgs/msys2/win-64\n",
      "                          https://repo.anaconda.com/pkgs/msys2/noarch\n",
      "          package cache : E:\\anaconda\\pkgs\n",
      "                          C:\\Users\\Supernova\\.conda\\pkgs\n",
      "                          C:\\Users\\Supernova\\AppData\\Local\\conda\\conda\\pkgs\n",
      "       envs directories : E:\\anaconda\\envs\n",
      "                          C:\\Users\\Supernova\\.conda\\envs\n",
      "                          C:\\Users\\Supernova\\AppData\\Local\\conda\\conda\\envs\n",
      "               platform : win-64\n",
      "             user-agent : conda/24.9.1 requests/2.32.2 CPython/3.12.4 Windows/11 Windows/10.0.26100 solver/libmamba conda-libmamba-solver/24.1.0 libmambapy/1.5.8 aau/0.4.4 c/. s/. e/.\n",
      "          administrator : False\n",
      "             netrc file : None\n",
      "           offline mode : False\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "!conda info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[-0.1115,  0.1204, -0.3696],\n",
       "        [-0.2404, -1.1969,  0.2093],\n",
       "        [-0.9724, -0.7550,  0.3239],\n",
       "        [-0.1085,  0.2103, -0.3908],\n",
       "        [ 0.2350,  0.6653,  0.3528]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "torch.manual_seed(123)\n",
    "torch.randn(5, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "torch.cuda.is_available()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 部署大语言模型云服务 API + 本地客户端"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. 前往硅基流动网站 https://cloud.siliconflow.cn/ 注册一个账号；\n",
    "2. 创建一个 API 密钥（注意密钥不要透露给他人）；\n",
    "3. 通过搜索网络上的相关教程，在自己的机器上安装一个大语言模型聊天客户端，例如 Cherry Studio、Chatbox、LM Studio 等；\n",
    "4. 在客户端中利用硅基流动的 API 调用大语言模型进行对话；\n",
    "5. 将上述流程中的核心步骤截图，插入到下面的单元格中，并加上必要的文字说明；\n",
    "6. 截图中需体现你调用了硅基流动的 API，比如硅基流动后台的调用记录等。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请在下方插入你安装客户端和调用 API 进行对话的步骤截图。Markdown 语法：`![](image.jpg)`，其中图片文件 `image.jpg` 和本 Notebook 处于同一个文件夹下，图片文件需一同上传 Gitee。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "首先我在硅基流动网站注册了一个账号，创建API密钥，如下图\n",
    "![](image1.png)\n",
    "然后，我下载了Cherry Studio，如图所示\n",
    "![](image2.png)\n",
    "然后我复制了硅基流动网站的API，输入到Cherry Studio中，现在我就可以利用硅基流动的API来调用大语言模型进行对话，如下图所示\n",
    "![](image3.png)![](image4.png)![](image5.png)\n",
    "为了证明我调用了硅基流动的API，我截图了我的API消费记录，从图image3可看到，我在Cherry Studio对话中用了776个token，硅基流动上的消费记录同时也记录我使用了776个token，因此可以证明我使用了硅基流动的API，消费记录如下\n",
    "![](image6.png)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
